package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.data.TestData;
import id.net.iconpln.bb.client.model.PageBbStockBean;
import id.net.iconpln.bb.client.model.PageBbSurveyorBean;
import id.net.iconpln.bb.client.model.PageBbUjiSamplingBean;
import id.net.iconpln.bb.client.model.Stock;
import id.net.iconpln.bb.client.service.ApprovalService;
import id.net.iconpln.bb.client.service.ApprovalServiceAsync;
import id.net.iconpln.bb.client.service.PortRPCService;
import id.net.iconpln.bb.client.service.PortRPCServiceAsync;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.MultiField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PageBbUjiSampling extends LayoutContainer {
	private final ApprovalServiceAsync service = GWT.create(ApprovalService.class);
	private FormBinding formBindings;  
	private FormData formData; 
	private ListStore storePenerimaan,storeKplAntri, storeJetty,storePengiriman;
	private Grid gridPenerimaan, gridKplAntri,gridPengiriman;
	private ComboBox cboJetty;
	private DateField tglTa, time_bongkarD,time_sandarD;
	private TextField<String> noAntri,ash_kirim,cv_kirim,ts_kirim,tm_kirim;
	private TimeField time_bongkarT,time_sandarT;
	
	
	  @Override  
	  protected void onRender(Element parent, int index) {  
	    super.onRender(parent, index);  
	    setLayout(new FitLayout());
	    initStore();
	    
	    formData = new FormData("-20"); 
	    ContentPanel cp = new ContentPanel();  
	   
	    cp.setHeaderVisible(false);
	    cp.setFrame(true);  
	    cp.setSize(900, 400);  
	    cp.setLayout(new RowLayout(Orientation.HORIZONTAL)); 
	  
	    gridPengiriman = createGridPengiriman();  
	    gridPengiriman.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
	    gridPengiriman.getSelectionModel().addListener(Events.SelectionChange,  
	        new Listener<SelectionChangedEvent<BaseModel>>() {  
	          public void handleEvent(SelectionChangedEvent<BaseModel> be) {  
	            if (be.getSelection().size() > 0) {  	              
	              formBindings.bind((ModelData) be.getSelection().get(0));  
	            } else {  
	              formBindings.unbind();  
	            }  
	          }  
	        });
	    
	    
	    gridPenerimaan = createGridPenerimaan();
//	    gridPenerimaan.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
//	    gridPenerimaan.getSelectionModel().addListener(Events.SelectionChange,  
//	        new Listener<SelectionChangedEvent<Stock>>() {  
//	          public void handleEvent(SelectionChangedEvent<Stock> be) {  
//	            if (be.getSelection().size() > 0) {  
//	              formBindings.bind((ModelData) be.getSelection().get(0));  
//	            } else {  
//	              formBindings.unbind();  
//	            }  
//	          }  
//	        });
	    ToolBar tbPltu = new ToolBar();
	    tbPltu.add(new LabelToolItem("<b>Data Penerimaan</b>"));
	    tbPltu.add(new SeparatorToolItem());
	    	    
	    ToolBar tbSandar = new ToolBar();
	    tbSandar.add(new LabelToolItem("<b>Data Pengiriman</b>"));
	    tbSandar.add(new SeparatorToolItem());
	    
	    FormPanel panel = createForm(); 
	    panel.setScrollMode(Scroll.AUTO);
	    formBindings = new FormBinding(panel, true);  
	    
	    
	    ContentPanel pkirim = new ContentPanel();
	    pkirim.setHeaderVisible(false);
	    pkirim.setLayout(new FitLayout());
	    pkirim.add(gridPenerimaan);
	    pkirim.setTopComponent(tbPltu);
	    
	    getListPengiriman();
	    
	    
	    ContentPanel pKplSandar = new ContentPanel();
	    pKplSandar.setHeaderVisible(false);
	    pKplSandar.setLayout(new RowLayout(Orientation.HORIZONTAL));
	    pKplSandar.add(gridPengiriman,new RowData(1, 1));
	    pKplSandar.setTopComponent(tbSandar);

	    ContentPanel pKplBongkar = new ContentPanel();
	    pKplBongkar.setHeaderVisible(false);
	    pKplBongkar.setLayout(new RowLayout(Orientation.HORIZONTAL));
	    pKplBongkar.add(gridPenerimaan,new RowData(1, 1));
	    pKplBongkar.setTopComponent(tbPltu);

	    
	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);
	    p.setLayout(new RowLayout(Orientation.VERTICAL));	    	    
	    p.add(pKplSandar, new RowData(.99, .5));
	    p.add(pKplBongkar, new RowData(.99, .5));
	    
	    cp.add(panel, new RowData(.4, 1));
	    cp.add(p, new RowData(.6, 1));
	    
	    
	    add(cp, new FitData(5));  
	  }  
	  private void initStore(){
		  storePenerimaan = new ListStore(); 
		  storePengiriman = new ListStore(); 
	  }

	  private Grid createGridPenerimaan() {  
		  
		    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	    	     

		    column = new ColumnConfig();  
		    column.setId("nama_pembangkit");  
		    column.setHeader("Nama Pembangkit");  
		    column.setWidth(150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("pemasok");  
		    column.setHeader("Nama Pemasok");  
		    column.setWidth(150);  
		    configs.add(column); 

		    
		    column = new ColumnConfig();  
		    column.setId("no_pengajuan");  
		    column.setHeader("No Pengajuan");    
		    column.setWidth(150);    
		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("no_sampling");  
		    column.setHeader("No Sampling");  
		    column.setWidth(100);  
		    configs.add(column);  	
		    
		    column = new ColumnConfig();  
		    column.setId("no_rakor");  
		    column.setHeader("No Rakor");  
		    column.setWidth(100);  
		    configs.add(column);  	  
		    
		    column = new ColumnConfig();  
		    column.setId("volume_kirim");  
		    column.setHeader("Volume Kirim");  
		    column.setWidth(100);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("volume_terima");  
		    column.setHeader("Volume Terima");  
		    column.setWidth(100);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("ash");  
		    column.setHeader("Volume Terima");  
		    column.setWidth(100);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("cv");  
		    column.setHeader("Volume Terima");  
		    column.setWidth(100);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("ts");  
		    column.setHeader("Volume Terima");  
		    column.setWidth(100);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("tm");  
		    column.setHeader("Volume Terima");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("hgi");  
		    column.setHeader("HGI");  
		    column.setWidth(100);  
		    configs.add(column);

		  
		ColumnModel cm = new ColumnModel(configs);  
	  
	    gridPenerimaan = new Grid(storePenerimaan, cm);  
	    gridPenerimaan.getView().setEmptyText("Data Empty");
	  

	    return gridPenerimaan;  
	  }   
	 
 
	  
	  private FormPanel createForm() {  
	    FormPanel panel = new FormPanel();	    
	    panel.setHeaderVisible(false);
	    
	    FieldSet fieldSet = new FieldSet();  
	    fieldSet.setHeading("Data Pengajuan");  
	    fieldSet.setCollapsible(false);
	    
	  
	    FormLayout layout = new FormLayout();  
	    layout.setLabelWidth(150);  
	    fieldSet.setLayout(layout);  

	    final TextField<String> no_pengajuan = new TextField<String>();  
	    no_pengajuan.setName("no_pengajuan");  
	    no_pengajuan.setFieldLabel("No Pengajuan");    
	    fieldSet.add(no_pengajuan, formData);	  	  
	    
	    final TextField<String> no_pengiriman = new TextField<String>();  
	    no_pengiriman.setName("no_pengiriman");  
	    no_pengiriman.setFieldLabel("No Pengiriman");    
	    fieldSet.add(no_pengiriman, formData);	  	 

	    final TextField<String> pemasok = new TextField<String>();	    
	    pemasok.setName("pemasok");  
	    pemasok.setFieldLabel("Pemasok");    
	    fieldSet.add(pemasok, formData);
	    
	    final TextField<String> idpemasok = new TextField<String>();  
	    idpemasok.setName("id_pemasok");  
	    idpemasok.setFieldLabel("Id Pemasok");
//	    idpemasok.setVisible(false);
	    fieldSet.add(idpemasok, formData);
	    
	    final TextField<String> idpltu = new TextField<String>();  
	    idpltu.setName("id_pltu");  
	    idpltu.setFieldLabel("Id Pltu");
//	    idpltu.setVisible(false);
	    fieldSet.add(idpltu, formData);
	    
	    final TextField<String> idkapal = new TextField<String>();  
	    idkapal.setName("id_kapal");  
	    idkapal.setFieldLabel("Id Kapal");
//	    idkapal.setVisible(false);
	    fieldSet.add(idkapal, formData);
	    
	    final TextField<String> volume = new TextField<String>();  
	    volume.setName("volume");  
	    volume.setFieldLabel("Volume");
//	    volume.setVisible(false);
	    fieldSet.add(volume, formData);
	    
	    final TextField<String> idpengiriman = new TextField<String>();  
	    idpengiriman.setName("id_pengiriman");  
	    idpengiriman.setFieldLabel("id Pengiriman");
//	    idpengiriman.setVisible(false);
	    fieldSet.add(idpengiriman, formData);

	    
	    TextField<String> kapal = new TextField<String>();
	    kapal.setName("nama_kapal");  
	    kapal.setFieldLabel("Nama Kpl / Tongkang");	    
	    fieldSet.add(kapal, formData);
	    
	    
	    panel.add(fieldSet);  	     

	    FieldSet fieldSet2 = new FieldSet();  
	    fieldSet2.setHeading("Kualitas & Kuantitas Pengiriman");  
	    fieldSet2.setCollapsible(false);

	    FormLayout layout3 = new FormLayout();  
	    layout3.setLabelWidth(80);  
	    fieldSet2.setLayout(layout3);  

	    MultiField multi_kirim = new MultiField();
	    multi_kirim.setFieldLabel("Ash");
	    multi_kirim.setSpacing(30);
	    
	    ash_kirim = new TextField<String>();
	    ash_kirim.setName("ash");
	    ash_kirim.setWidth(90);
	    multi_kirim.add(ash_kirim);   	    
	    
	    LabelField lcv = new LabelField("CV:");
	    lcv.setWidth(20);
	    multi_kirim.add(lcv);
	    
	    cv_kirim = new TextField<String>();	    
	    cv_kirim.setName("cv");  
	    cv_kirim.setWidth(90);

	    multi_kirim.add(cv_kirim);
	    
	    fieldSet2.add(multi_kirim, formData);
	    
	    MultiField multi_kirim_tm_ts = new MultiField();
	    multi_kirim_tm_ts.setFieldLabel("TM");
	    multi_kirim_tm_ts.setSpacing(30);
	    
	    tm_kirim = new TextField<String>();
	    tm_kirim.setName("tm");  
	    tm_kirim.setFieldLabel("TM");    
	    tm_kirim.setWidth(90);
	    
	    multi_kirim_tm_ts.add(tm_kirim);
	    
	    LabelField lts = new LabelField("TS:");
	    lts.setWidth(20);
	    multi_kirim_tm_ts.add(lts);
	    
	    
	    ts_kirim = new TextField<String>();
	    ts_kirim.setName("ts");  
	    ts_kirim.setWidth(90);
	    
	    multi_kirim_tm_ts.add(ts_kirim);
	    
	    fieldSet2.add(multi_kirim_tm_ts, formData);
	    
	    TextField<String> hgi_kirim1 = new TextField<String>();
	    hgi_kirim1.setName("hgi");  
	    hgi_kirim1.setWidth(90);
	    hgi_kirim1.setFieldLabel("HGI");    
	    fieldSet2.add(hgi_kirim1, formData);	    
	    	    	   
	    final TextField<String> vol_kirim1 = new TextField<String>();
	    vol_kirim1.setName("volume");  
	    vol_kirim1.setFieldLabel("Kuantitas");	    
	    fieldSet2.add(vol_kirim1, formData);
	    
	    panel.add(fieldSet2);
	    
	    //start
	    FieldSet fieldSet3 = new FieldSet();  
	    fieldSet3.setHeading("Kualitas & Kuantitas Penerimaan");  
	    fieldSet3.setCollapsible(false);

	    FormLayout layout4 = new FormLayout();  
	    layout4.setLabelWidth(80);  
	    fieldSet3.setLayout(layout4);  

	    MultiField multi_terima = new MultiField();
	    multi_terima.setFieldLabel("Ash");
	    multi_terima.setSpacing(30);
	    
	    final TextField<String> ash_terima = new TextField<String>();
	    ash_terima.setWidth(90);
	    multi_terima.add(ash_terima);   	    
	    
	    LabelField lcv_terima = new LabelField("CV:");
	    lcv_terima.setWidth(20);
	    multi_terima.add(lcv_terima);
	    
	    final TextField<String> cv_terima = new TextField<String>();	    
	    cv_terima.setWidth(90);

	    multi_terima.add(cv_terima);
	    
	    fieldSet3.add(multi_terima, formData);
	    
	    MultiField multi_terima1 = new MultiField();
	    multi_terima1.setFieldLabel("TM");
	    multi_terima1.setSpacing(30);
	    
	    final TextField<String> tm_terima = new TextField<String>();
	    tm_terima.setFieldLabel("TM");    
	    tm_terima.setWidth(90);
	    
	    multi_terima1.add(tm_terima);
	    
	    LabelField lts_terima = new LabelField("TS:");
	    lts_terima.setWidth(20);
	    multi_terima1.add(lts_terima);
	    
	    
	    final TextField<String> ts_terima = new TextField<String>();
	    ts_terima.setWidth(90);
	    
	    multi_terima1.add(ts_terima);
	    
	    fieldSet3.add(multi_terima1, formData);
	    
	    final TextField<String> hgi_terima = new TextField<String>();
	    hgi_terima.setWidth(90);
	    hgi_terima.setFieldLabel("HGI");    
	    fieldSet3.add(hgi_terima, formData);	    
	    	    	   
	    final TextField<String> vol_terima = new TextField<String>();
	    vol_terima.setFieldLabel("Kuantitas");	    
	    fieldSet3.add(vol_terima, formData);
	    
	    final SimpleComboBox<String> surveyor = new SimpleComboBox<String>();  
	    surveyor.setFieldLabel("Surveyor");
	    surveyor.setValueField("30");
	    surveyor.setForceSelection(true);  
	    surveyor.setTypeAhead(true);   
	    surveyor.setTriggerAction(TriggerAction.ALL);
	    surveyor.add("PT. KIDECO JAYA AGUNG");
	    surveyor.add("PT. KALTIM PRIMA COAL");
	    surveyor.add("PT. ARUTMIN");
	    fieldSet3.add(surveyor, formData);
	    
	    panel.add(fieldSet3);
	    //finish
	    
	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);	    
	    p.setButtonAlign(HorizontalAlignment.RIGHT);  
	    
	    p.addButton(new Button("Submit", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {  
//		    	    MessageBox.alert("msg", "setvaluefield: " + surveyor.getValueField() , null);
		    	  
		    	    Map mapParam = new FastMap();
		    	    mapParam.put("id_pemasok", idpemasok.getValue());
		    	    mapParam.put("id_pltu", idpltu.getValue());
		    	    mapParam.put("id_kapal", idkapal.getValue());
		    	    mapParam.put("volume", volume.getValue());
		    	    mapParam.put("no_pengajuan", no_pengajuan.getValue());
		    	    mapParam.put("id_pengiriman", idpengiriman.getValue());
		    	    mapParam.put("no_pengiriman", no_pengiriman.getValue());
		    	    mapParam.put("id_surveyor", surveyor.getValueField());
		    	    mapParam.put("jumlah_sampling", "6");
		    	    mapParam.put("vol_terima", vol_terima.getValue());
		    	    mapParam.put("vol_kirim", vol_kirim1.getValue());
		    	    mapParam.put("status", "TERIMA");
		    	    mapParam.put("ash", ash_terima.getValue());
		    	    mapParam.put("tm", tm_terima.getValue());
		    	    mapParam.put("ts", ts_terima.getValue());
		    	    mapParam.put("cv", cv_terima.getValue());
		    	    mapParam.put("hgi", hgi_terima.getValue());
		    	    mapParam.put("user", "REZA");
		    		mapParam.put("app_access", "WEB");
		    		mapParam.put("crud", "CREATE_APPROVAL");
		    		

		    		service.insertBbPengirimanBb("SAMPLING", mapParam,new AsyncCallback<List<Map>>() {
		    			public void onFailure(Throwable caught) {
		    				GWT.log(caught.getMessage(), null);
		    			}

		    			public void onSuccess(List<Map> result) {
		    				MessageBox.alert("Pesan", "Data berhasil di Simpan", null);
//		    				System.out.println("masuk on sucses");
//		    				gridPengiriman.mask("load Data ....","x-mask-loading");
//		    				storePenerimaan.removeAll();
//		    				getListPengiriman();
//		    				gridPengiriman.unmask();
		    			}
		    		});
		    		gridPengiriman.getStore().commitChanges(); 
		      }  
		    }));  
	    
	    p.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
	      @Override  
	      public void componentSelected(ButtonEvent ce) { 
	    	  
	      }  
	    }));  
	    

	    panel.add(p);
	    
	    return panel;  
	  }  
	  private Grid createGridPengiriman() {  
		  
		    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	    	     
		    
		    column = new ColumnConfig();  
		    column.setId("no_pengajuan");  
		    column.setHeader("No Pengajuan");  
		    column.setWidth(150);  
		    configs.add(column); 

		    
		    column = new ColumnConfig();  
		    column.setId("no_pengiriman");  
		    column.setHeader("No Pengiriman");    
		    column.setWidth(150);    
		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("pemasok");  
		    column.setHeader("Pemasok");  
		    column.setWidth(100);  
		    configs.add(column);  	
		    
		    column = new ColumnConfig();  
		    column.setId("nama_kapal");  
		    column.setHeader("Nama Kapal");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("tgl_ta");  
		    column.setHeader("Tanggal TA");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("tgl_ta");  
		    column.setHeader("Tanggal TD");  
		    column.setWidth(100);  
		    configs.add(column);

		    column = new ColumnConfig();  
		    column.setId("ash");  
		    column.setHeader("ASH");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("cv");  
		    column.setHeader("CV");  
		    column.setWidth(100);  
		    configs.add(column);

		    column = new ColumnConfig();  
		    column.setId("ts");  
		    column.setHeader("TS");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("tm");  
		    column.setHeader("TM");  
		    column.setWidth(100);  
		    configs.add(column);

		    column = new ColumnConfig();  
		    column.setId("hgi");  
		    column.setHeader("HGI");  
		    column.setWidth(100);  
		    configs.add(column);
		    
		    
		 ColumnModel cm = new ColumnModel(configs);  
	  
	    gridPengiriman = new Grid(storePengiriman, cm);  
	    gridPengiriman.getView().setEmptyText("Data Empty");
	    gridPengiriman.setBorders(true);
	    gridPengiriman.addListener(Events.CellClick, new Listener<BaseEvent>() {            
        public void handleEvent(BaseEvent ge) {
        	try{
        		ash_kirim.setValue(gridPengiriman.getSelectionModel().getSelectedItem().get("ash").toString());
            	cv_kirim.setValue(gridPengiriman.getSelectionModel().getSelectedItem().get("cv").toString());
            	ts_kirim.setValue(gridPengiriman.getSelectionModel().getSelectedItem().get("ts").toString());
            	tm_kirim.setValue(gridPengiriman.getSelectionModel().getSelectedItem().get("tm").toString());
            	String no_pengajuan =  gridPengiriman.getSelectionModel().getSelectedItem().get("no_pengajuan").toString();
                String id_pltu = gridPengiriman.getSelectionModel().getSelectedItem().get("id_pltu").toString();
            	
                
                System.out.println("no pengajuan: " + no_pengajuan);
                System.out.println("id pltu: " + id_pltu);
            	getListPenerimaan(no_pengajuan, id_pltu);
            	
            	
        	}catch (Exception e) {
					// TODO: handle exception
        		e.getMessage();
				}

         	
        }
		});

	    return gridPengiriman;  
	  }   

	  private void getListPengiriman(){
		  Map mapParam = new FastMap();
  		  mapParam.put("id_pltu", "2");
  		  
  		  	service.getlistpengiriman_approval("PENGIRIMAN_APPROVAL", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storePengiriman.removeAll();
  				storePengiriman.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		  });
	  }
	  
	  private void getListPenerimaan(String no_pengajuan, String id_pltu){
		  Map mapParam = new FastMap();
		  mapParam.put("no_pengajuan", no_pengajuan);
  		  mapParam.put("id_pltu", id_pltu);
  		  
  		System.out.println("no pengajuan map: " + mapParam.get("no_pengajuan").toString());
        System.out.println("id pltu map: " + mapParam.get("id_pltu").toString());
  		  
  		  	service.getlistpengiriman_approval("SAMPLING_APPROVAL", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storePenerimaan.removeAll();
  				storePenerimaan.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		  });
	  }
	  
}
